import matplotlib.pyplot as plt #载入matplotlib.pyplot模块
import numpy as np
import pandas as pd

fig = plt.figure(figsize=(8,5))
complaints = pd.read_csv('data/311-service-requests.csv')
complaints['Complaint Type'].value_counts().head().plot(kind='bar')
data=complaints['Complaint Type'].value_counts().head()
print(data)
plt.xticks(range(len(data.index)),['HEATING','CONSTRUCTION','LIGHT CONDITION','PLUMBING','DOF REQUEST'],rotation=30,fontsize=10)
x=range(len(data.index))
y=list(data.values)
print(y)
#添加文本数字信息
for a,b in zip(x,y):
    plt.text(a, b+100,str(b), ha='center', va= 'bottom',fontsize=12)
plt.title('Complain Type Top5',fontsize=20)
plt.ylim(0,15000)
plt.savefig('Image.png',dpi=300,bbox_inches='tight')
plt.show()